
var fn_index = async (ctx, next) => {
    ctx.response.body = `<h1>Index</h1>
        <form action="/signIn" method="post">
            <p>Name: <input name="name" value="Koa"></p>
            <p>Password: <input name="password" type="password"></p>
            <p><input type="submit" value="Submit"></p>
        </form>`
    // next()
}

var fn_sign = async (ctx, next) => {
    var name = ctx.request.body.name || ''
    password = ctx.request.body.password || ''
    console.log(`signin with name:${name}, password:${password}`)
    if (name === 'Koa' && password === '123456') {
        ctx.response.body = `<h1>Welcome ${name}</h1>`
    } else {
        ctx.response.body = `<h1>Login fail</h1>
                              <p><a href="./">Try again</a></p>`
    }
}

var not_find = async (ctx, next) => {
    ctx.response.body = '<h1>页面找不到</h1>'
}

module.exports = {
    'GET /' : fn_index,
    'POST /signIn': fn_sign,
    'GET /404': not_find
}